using ActiveRecord;

	
/*
CREATE TABLE `customers` (
  `id` int(11) NOT NULL auto_increment,
  `sales_rep_id` int(11) NULL,
  `name` varchar(40) NOT NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)
*/
   [HasMany(Table="orders")]
   [BelongsTo(Table="sales_reps")]
   public class Customer : ActiveRecordBase {}

/*
CREATE TABLE `orders` (
  `id` int(11) NOT NULL auto_increment,
  `customer_id` int(11) NOT NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NULL default NULL,
  PRIMARY KEY  (`id`)
)
*/
	[ActiveRecord(TableName="orders")]
   [BelongsTo(Table="customers", ForeignKey="customer_id")]
	public class Order : ActiveRecordBase {}

/*
CREATE TABLE `sales_reps` (
  `id` int(11) NOT NULL auto_increment,
  `person_id` int(11) NOT NULL, 
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NULL default NULL,
  PRIMARY KEY  (`id`)
)
*/
	[HasMany(Table="customers")]
   [ActiveRecord(TableName="sales_reps")]
	public class SalesRep : Person {}


/*
CREATE TABLE `players` (
  `player_id` int(11) NOT NULL,
  `stat_ref_code` varchar(25) NOT NULL,
  `player_name` varchar(55) NOT NULL
)
*/
	[ActiveRecord(PrimaryKey="player_id")]
	public class Player : ActiveRecordBase {}

/*
CREATE TABLE `post_table` (
  `id` int(11) NOT NULL auto_increment,
  `parent_id` int(11) NOT NULL,
  `type_code` char(1) NOT NULL,
  `title` varchar(127) default NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)
*/
   [ActiveRecord(TableName="post_table")]
   [BelongsTo(Table="blog_table", OrderBy="created_on, updated_on", Lazy=false, ForeignKey="parent_id")]
   public class Post : ActiveRecordBase {}
   
/*
CREATE TABLE `blog_table` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(127) default NULL,
  `post_count` int(11) default 0,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)
*/
   [ActiveRecord(TableName="blog_table")]
   [HasMany(Table="post_table", Conditions="type_code = 'B'", OrderBy="created_on, updated_on", Lazy=false, AssociationForeignKey="parent_id")]
   public class Blog : ActiveRecordBase {}
   
   
/*
CREATE TABLE `people` (
  `id` int(11) NOT NULL auto_increment,
  `first_name` varchar(127) default NULL,
  `last_name` varchar(127) default NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)
*/
   public class Person : ActiveRecordBase{}
   
/*
CREATE TABLE `developers_projects` (
  `developer_id` int(11) NOT NULL,
  `project_id` int(11) NOT NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`developer_id`, `project_id`)
)
*/
/*
CREATE TABLE `developers` (
  `id` int(11) NOT NULL auto_increment,
  `person_id` int(11) NOT NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)
*/

   [HasAndBelongsToMany(Table="projects")]
   public class Developer : Person { }

   
/*
CREATE TABLE `projects` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(127) default NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)
*/
   [HasAndBelongsToMany(Table="developers")]
   public class Project : ActiveRecordBase { }


/*
CREATE TABLE `companies` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(127) default NULL,
  `type` varchar(31) default NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)
*/
   public class Company : ActiveRecordBase {}
   public class Firm : Company {}
   public class Client : Company {}
   public class PriorityClient : Client {}


/*
CREATE TABLE `companies_2` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(127) default NULL,
  `type_id` varchar(31) default NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)
*/

   [ActiveRecord(TableName="companies_2", InheritanceColumn="type_id")]
   public class Company2 : ActiveRecordBase {}
   public class Firm2 : Company {}


// same as previous, expect uses HABTM.Through
   [HasAndBelongsToMany(ClassName="Project2", Through="developers_projects")]
   [ActiveRecord(TableName="developers")]
   public class Developer2 : Person { }


   [HasAndBelongsToMany(ClassName="Developer2", Through="developers_projects")]
   [ActiveRecord(TableName="projects")]
   public class Project2 : ActiveRecordBase { }

// same as previous, expect eager
   [HasAndBelongsToMany(ClassName="Project4", Through="developers_projects", Lazy=false)]
   [ActiveRecord(TableName="developers")]
   public class Developer4 : Person { }

   [HasAndBelongsToMany(ClassName="Developer4", Through="developers_projects", Lazy=false)]
   [ActiveRecord(TableName="projects")]
   public class Project4 : ActiveRecordBase { }

// Another way to declare the many to many relationship
   [HasMany(ClassName="Developer3", Through="developers_projects")]
   [HasMany(Table="developers_projects")]
   [ActiveRecord(TableName="projects")]
   public class Project3 : ActiveRecordBase {  }

   [HasMany(ClassName="Project3", Through="developers_projects")]
   [HasMany(Table="developers_projects")]
   [ActiveRecord(TableName="developers")]
   public class Developer3 : Person { }

// same as prev except eager
   [HasMany(ClassName="Developer5", Through="developers_projects", Lazy=false)]
   [HasMany(Table="developers_projects")]
   [ActiveRecord(TableName="projects")]
   public class Project5 : ActiveRecordBase {  }

   [HasMany(ClassName="Project5", Through="developers_projects", Lazy=false)]
   [HasMany(Table="developers_projects")]
   [ActiveRecord(TableName="developers")]
   public class Developer5 : Person { }


